<template>
  <div>
    <cephalosome/>
    <el-row class="banner">
        <el-row class="row">
          <el-row class="bannerbox"> 
              <p class="Organic"><span>Organic</span> Foods at<br/>your  <span> Doorsteps</span></p>
              <p style="font-size:24px" class="banner-p">Dignissim massa diam elementum.</p>
              <p>
                <input type="button" value="START SHOPPING">
                <input type="button" value="JOIN NOW">
              </p>
              <el-row style="height: 80px;">
                <div class="banner-line">
                    <div>14K+</div>
                    <div>
                        PRODUCT <br/>
                        VARIETIES
                    </div>
                </div>
                <div class="banner-line">
                    <div>50K+</div>
                    <div>
                        HAPPY <br/>
                        CUSTOMERS
                    </div>
                </div>
                <div class="banner-line">
                    <div>10K+</div>
                    <div>
                        STORE <br/>
                        LOCATIONS
                    </div>
                </div>
              </el-row>
              <el-row>
                <div class="row">
                    
                    <div></div>
                </div>
              </el-row>
          </el-row>
        </el-row>
    </el-row>
    <el-row class="Category">
      <div class="row">种类</div>
      <div class="Categorybox">
        <div v-for="(item,index) in categorylist" :key="index">
          <el-row><img :src="'../images/'+item.categoryImg"/></el-row>
          <p>{{item.categoryName}}</p>
        </div>
      </div>
    </el-row>
    <el-row class="products">
      <div class="row">最畅销产品</div>
      <div class="productsbox">
        <div class="productslist" v-for="(item,index) in foodlist" :key="index">
            <div class="productslistone">
                <img :src="'../images/'+item.foodImg" @click="single(item.foodName)">
                <p><span>-30%</span><span class="el-icon-star-off"></span></p>
            </div>
            <p>{{item.foodName}}</p>
            <p>
              <span>1 UNIT</span> 
              <el-rate style="margin-left: 10px;"
                v-model="value"
                disabled
                show-score
                text-color="#ff9900"
                score-template="{value}">
              </el-rate>
            </p>
            <h4>￥{{item.foodPrice}}</h4>
            <p class="car">
              <el-input-number style="width:130px" v-model="item.num" :min="0" :max="10" ></el-input-number>
              <span>加入购物车</span>
            </p>
        </div>
      </div>
    </el-row>
    <el-row class="bannerproducts">
        <div class="bannerproductsone">
            <h1>Items om SALE</h1>
            <h3>Discounts up to 30%</h3>
            <h3>SHOP NOW</h3>
        </div>
        <div class="bannerproductstwo">
          <div>
              <h1>Combo offers</h1>
              <h3>Discounts up to 50%</h3>
              <h3>SHOP NOW</h3>
          </div>
          <div>
              <h1>Discount Coupons</h1>
              <h3>Discounts up to 40%</h3>
              <h3>SHOP NOW</h3>
          </div>
        </div>
    </el-row>
    <el-row class="boom">
      <div class="row">主打产品</div>
      <div class="boombox">
        <div class="boomlist" v-for="(item,index) in foodlist" :key="index">
            <div class="boomlistone">
                <img :src="'../images/'+item.foodImg" @click="single(item.foodName)">
                <p><span>-30%</span><span class="el-icon-star-off"></span></p>
            </div>
            <p>{{item.foodName}}</p>
            <p>
              <span>1 UNIT</span> 
              <el-rate style="display: inline-block; margin-left: 10px;"
                v-model="value"
                disabled
                show-score
                text-color="#ff9900"
                score-template="{value}">
              </el-rate>
            </p>
            <h4>￥{{item.foodPrice}}</h4>
            <p class="car">
              <el-input-number style="width:130px" v-model="item.num" :min="0" :max="10" ></el-input-number>
              <span>加入购物车</span>
            </p>
        </div>
      </div>
    </el-row>
    <el-row class="join_member">
      <div class="join_memberlist">
          <div>
            <h1>Get 25% Discount on</h1>
            <h1>your first purchase</h1>
            <p>Just Sign Up &amp; Register it now to become member</p>
          </div>
          <div>
                <form>
                    <input placeholder="Enter your Name" type="text"/>
                    <input placeholder="Enter your Email Address" type="text"/>
                    <input  type="submit" value="Submit"/>
                </form>
          </div>
      </div>
    </el-row>
    <!-- <el-row class="Just_bought">
      <div class="row">刚刚售出</div>
      <div class="Just_boughtbox"> -->
        <!-- <div class="Just_boughtlist" v-for="(item,index) in orderlist" :key="index">
            <div class="Just_boughtlistone">
                <img :src="'../images/'+item.foodImg">
                <p><span>-30%</span><span class="el-icon-star-off"></span></p>
            </div>
            <p>{{item.foodName}}</p>
            <p>
              <span>1 UNIT</span> 
              <el-rate style="display: inline-block; margin-left: 10px;"
                v-model="value"
                disabled
                show-score
                text-color="#ff9900"
                score-template="{value}">
              </el-rate>
            </p>
            <h4>￥{{item.foodPrice}}</h4>
            <p class="car">
              <el-input-number style="width:130px" v-model="item.num" :min="0" :max="10" ></el-input-number>
              <span>加入购物车</span>
            </p>
        </div> -->
      <!-- </div> -->
    <!-- </el-row> -->
    <el-row class="Recent_blog">
        <div class="row">最近博客</div>
        <div class="Recent_bloglist" v-for="(item,index) in bloglist" :key="index">
            <div class="Recent_bloglistone">
                <img :src="'../images/'+item.blogImg" >
            </div>
            <p>{{item.blogDate}}</p>
            <p>{{item.blogTitle}}</p>
            <p>{{item.blogDetails}}</p>
        </div>
    </el-row>
    <tail/>
  </div>
</template>
<script>
import cephalosome from './header.vue'
import tail from './demo.vue'
import { getcategorylist ,selectfoodlist,selectbloglist,selectOrderlist} from '../api/api.js'

export default {
  name:"index",
  data() {
    return {
        value:1.5,
        categorylist:[],
        orderlist:[],
        foodlist:[],
        bloglist:[]
    }
  },
  methods: {
      getcategory(){
        let that=this;
        getcategorylist().then(res => {
            that.categorylist = res || [];
            console.log(that.categorylist);
        }).catch(error => {
          console.log("错误信息:"+error);
        })
      },
      selectfood(){
        let that=this;
        selectfoodlist().then(res => {
            that.foodlist = res;
            that.foodlist = res.map(item => ({ ...item, num: 0 })); // 为每个产品添加 num 属性
            console.log(that.foodlist);
        }).catch(error => {
          console.log("错误信息:"+error);
        })
      },
      getorderlist(){
          let that=this;
          selectOrderlist().then(res=>{
              console.log(res);
              // that.orderlist=res.data;
              // that.foodlist = res.data.map(item => ({ ...item, num: 0 })); // 为每个产品添加 num 属性
              // console.log(that.orderlist);
              // console.log(that.orderlist[0].orderFoodname);
              
          }).catch(error=>{
            console.log("错误信息:"+error);
          })
      },
      getblog(){
        let that=this;
        selectbloglist().then(res => {
            that.bloglist = res;
            console.log(that.bloglist);
        }).catch(error => {
          console.log("错误信息:"+error);
        })
      },
        single(name){
           this.$router.push({ name: 'single', params: { name: name } });
        }
  },
  components: { 
    cephalosome,
    tail
  },
  created(){
    console.log("你好这是首页")
    this.getcategory()
    this.selectfood()
    this.getblog()
    this.getorderlist()
  }
  
}
</script>
<style scoped>
  .banner{
    width: 100%;
    height: 728.4px;
    background-image: url(../images/banner-1.jpg);
    background-repeat: no-repeat;
    background-size: cover;
  }
  .bannerbox{
    width: 1600px;
    height: 725.2px;
    margin: 0 auto;
    padding: 80px 20px 0 20px;
  }
  .Organic{
    font-size: 80px;
    line-height: 90px;
    margin:0 0 20px 0;
  }
  .Organic span:first-child {
    font-weight: bold;
    color: #64a54a;
  }
  .Organic span:last-child {
    font-weight: bold;
  }
  .banner-p{
    color: #5f696a;
  }
  .bannerbox input{
    height: 55px;
    border-radius: 50px;
    margin: 10px 10px 20px 0;
    padding: 20px 25px;
    text-align: center;
    background-color: #212529;
    color: white;
    border: 0px;
    font-size: 15px;
  }
  .bannerbox input:first-child{
    background-color: #64a54a;
  }
  .banner-line{
    display: inline-block;
    margin-right: 25px;
  }
  .banner-line div{
    height: 80px;
    display: inline-block;
    margin-right: 25px;
  }
  .banner-line div:first-child{
    font-size: 40px;
    font-weight: bold;
  }
  .Category{
    width: 1600px;
    height: 350px;
    margin: 0 auto;
    margin-top: 50px;
  }
  .Category img{
    Border-radius:100px;
  }
  .Category .row:first-child ,.products .row:first-child,.boom .row:first-child,
  .Just_bought .row:first-child,.Recent_blog .row:first-child{
    font-size:34px;
    font-weight: bold;
    margin: 0 0 40px 0;
  }
  .Categorybox{
    width: 1500px;
    display: flex;
  }
  .Categorybox div{
    text-align: center;
    display: inline-block;
    flex-grow: 1;
  }
  .products{
    width: 1600px;
    margin: 0 auto;
    margin-top: 50px;
  }
  .productslist{
    width: 250px;
    height: 370px;
    padding: 20px;
    display: inline-block;
    margin: 0 8px;
  }
  .productslist:hover,.boomlist:hover,.Just_boughtlist:hover{
    box-shadow: 0px 21px 44px rgba(0, 0, 0, 0.08);
  }
  .productslist p,.boomlist p,.Just_boughtlist p{
    line-height: 20px;
    margin: 10px 0 0 0;
  }
  .productslistone,.boomlistone,.Just_boughtlistone{
      background-color: #f1ecf4;
      border-radius: 10px;
      width: 240px;
      height: 210px;
      margin: 0;
  }
  .productslistone p,.boomlistone p,.Just_boughtlistone p{
    float: left;
    position: relative;
    bottom: 210px;
    margin: 0;
    height: 0;
    line-height: 0px;
    margin: 0 10px;
  }
  .productslistone img,.boomlistone img,.Just_boughtlistone img{
    width: 240px;
    height: 210px;
  }
  .productslistone span:first-child,.boomlistone span:first-child,.Just_boughtlistone span:first-child{
    float: left;
    width: 50px;
    display: inline-block;
    height: 25px;
    line-height: 25px;
    color: white;
    background-color: #a3be4c;
    font-weight: bold;
    text-align: center;
    margin: 10px;
    font-size: 12px;
    border-radius: 8px;
  }
  .productslistone span:last-child,.boomlistone span:last-child,.Just_boughtlistone span:last-child{
    width: 45px;
    height: 45px;
    display: inline-block;
    border-radius: 45px;
    line-height: 45px;
    border: #d2d4d4 1px solid;
    margin: 5px 10px 0 90px;
  }
  .productslistone span:last-child:hover,.boomlistone span:last-child:hover,.Just_boughtlistone span:last-child:hover{
    background-color: #f03838;
    color: white;
  }
  .el-icon-star-off{
    font-size: 23px;
    font-weight: bold;
    text-align: center;
  }
  .productslist h4,.boomlist h4,.Just_boughtlist h4{
    font-size: 25px;
    margin: 0;
  }
  .productslist p:nth-child(3),.boomlist p:nth-child(3),.Just_boughtlist p:nth-child(3){
    color: #5f696a;
    font-size: 13px;
  }
  .car span{
    float: right;
    color: #5f696a;
    font-size: 13px;
    margin: 0 10px;
  }
  
  .bannerproducts{
    width: 1600px;
    margin: 0 auto;
    padding: 20px 0;
    color: white;
  }
  .bannerproductsone{
    float: left;
    width: 810px;
    display: inline-block;
    background-image: url(../images/banner-ad-1.jpg);
    height: 310px;
    padding: 150px 0 0 50px;
  }
  .bannerproductstwo{
    float: left;
  }
  .bannerproductstwo div:first-child{
    width: 600px;
    height: 200px;
    display: block;
    margin: 0 0 10px 20px;
    padding: 25px 0 0 50px;
    background-image: url(../images/banner-ad-2.jpg);
  }
  .bannerproductstwo div:last-child{
    width: 600px;
    height: 200px;
    display: block;
    margin-left: 20px;
    padding: 25px 0 0 50px;
    background-image: url(../images/banner-ad-3.jpg);
  }
  .boom,.Just_bought{
    width: 1600px;
    height: 520px;
    overflow: hidden;
    margin: 0 auto;
  }
  .boomlist,.Just_boughtlist{
    float: left;
    margin: 10px 12px;
    padding: 20px;
  }
  .join_member{
    width: 1470px;
    height: 380px;
    margin: 40p 0;
    margin: 0 auto;
    color: white;
  }
  .join_memberlist{
    width: 1190px;
    height: 280px;
    margin: 0 auto;
    background-image: url(../images/banner-newsletter.jpg);
    background-repeat: no-repeat;
    padding: 80px 0 0 200px;
  }
  .join_memberlist h1{
    line-height: 20px;
    font-size: 50px;
  }
  .join_memberlist div{
    float: left;
    display: inline-block;
  }
  .join_memberlist form{
    margin:30px 0 0 80px;
  }
  .join_memberlist form input{
    border: 0;
    width: 390px;
    height: 20px;
    display: block;
    padding: 5px;
    margin-bottom: 13px;
  }
  .join_memberlist form input:last-child{
    width: 400px;
    height: 30px;
    background-color: #212529;
    color: white;
  }
  .Recent_blog{
    width: 1600px;
    height: 620px;
    overflow: hidden;
    margin: 0 auto;
  }
  .Recent_bloglist{
    display: inline-block;
    float: left;
    padding: 20px;
    width: 450px;
    height: 460px;
    border-radius: 5px;
    margin: 5px;
    box-shadow: 0px 21px 44px rgba(0, 0, 0, 0.08);
  }
  .Recent_bloglist img{
    width: 450px;
    border-radius: 5px;
  }
  .Recent_bloglist p{
    line-height: 30px;
    padding: 0 20px;
    margin: 10px 0;
  }
  .Recent_bloglist p:nth-child(2),.Recent_bloglist p:last-child{
    color: gray;
  }
  .Recent_bloglist p:nth-child(3){
    font-size: 30px;
    font-weight: bold;
  }
</style>
